package com.example.demo.common;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * 图形验证码工具类
 */
@Component
public class CheckCodeTools {

    @Value("${imgpath}")
    private String imagePath;

    public String[] createImage(){
        String imageName = UUID.randomUUID().toString()+".png";

        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(320,40,5,20);

        lineCaptcha.write(imagePath+imageName);

        String code  = lineCaptcha.getCode();
        String[] result = new String[]{imageName,code};
        return result;
    }
}
